import 'package:flutter/material.dart';
import '../order/orderlist.dart';
class OrderPage extends StatefulWidget {
  Map arguments;
  OrderPage({Key key, this.arguments,}) : super(key: key);

  @override
  _OrderPageState createState() => _OrderPageState(arguments: this.arguments);
}

class _OrderPageState extends State<OrderPage>with SingleTickerProviderStateMixin {
   TabController _tabController;
    int _currentIndex = 2; //选中下标
  Map arguments;
  _OrderPageState({this.arguments});
  int count=0;
  @override
  void initState(){
    super.initState();
    _tabController=new TabController(length: 5, vsync: this);
    _tabController.index=this.arguments['id'];
    //  _tabController.addListener(() {
    //    _onTabChanged();
    // });
     _tabController.addListener(() => _onTabChanged());
    //_tabController=this.arguments['id'];
  }
   _onTabChanged() {
    if (_tabController.index.toDouble() == _tabController.animation.value) { 
      //赋值 并更新数据
      setState(() {
        print(_tabController.index);
        _currentIndex = _tabController.index;
      });
      // getDetail();
    } 
  }
  @override
  Widget build(BuildContext context) {
    return Container(
       child: Scaffold(
         appBar: AppBar(
           backgroundColor: Colors.blue[200],
           title: Text('订单'),
           bottom: TabBar(
             labelColor: Colors.orangeAccent,
             indicatorColor:Colors.orangeAccent,
             unselectedLabelColor:Colors.white,
             isScrollable: true,
             onTap: (value){
               this.count=value;
               print(value);
             },
              controller: this._tabController,
             tabs: <Widget>[
               Text('全部'),
               Text('代付款'),
               Text('代发货'),
               Text('待收货'),
               Text('待评价')
             ]
             ),
         ),
         body: IndexedStack(
           children: <Widget>[
             Container(
               child: TabBarView(
                 controller: this._tabController,
                // controller: this._tabController,
                 children: <Widget>[
                 OrderListPage(arguments:{"id":0}),
                  OrderListPage(arguments:{"id":1}),
                   OrderListPage(arguments:{"id":2}),
                    OrderListPage(arguments:{"id":3}),
                     OrderListPage(arguments:{"id":4}),
               ]),
             )
           ],
         ),
       ),
    );
  }
}